<!DOCTYPE html>
<html lang="zh-CN" data-bs-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>科讯聚合平台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .card-title a {
            text-decoration: none;
            color: #212529;
        }
        .card-title a:hover {
            color: #0d6efd;
        }
        .card {
            transition: transform 0.2s ease-in-out;
        }
        .card:hover {
            transform: translateY(-5px);
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark shadow-sm">
        <div class="container">
            <a class="navbar-brand" href="/">科讯聚合平台</a>
        </div>
    </nav>

    <main class="container mt-4">
        <!-- Flash 消息显示区域 -->
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <div class="card mb-4">
            <div class="card-body">
                <h5 class="card-title">按需抓取</h5>
                <p class="card-text">点击按钮，立即抓取指定分类的最新文章。</p>
                {% for cat_name in categories %}
                    <a href="{{ url_for('main.scrape_now', category_name=cat_name) }}" class="btn btn-primary btn-sm">抓取: {{ cat_name }}</a>
                {% endfor %}
            </div>
        </div>

        <!-- 分类筛选区域 -->
        <div class="card mb-4">
            <div class="card-body">
                <h5 class="card-title">分类查看</h5>
                <p class="card-text">点击链接，只看您感兴趣的分类。</p>
                <a href="{{ url_for('main.index') }}" class="btn btn-outline-secondary btn-sm">全部</a>
                {% for cat_name in categories %}
                    <a href="{{ url_for('main.show_category', category_name=cat_name) }}" class="btn btn-outline-info btn-sm">{{ cat_name }}</a>
                {% endfor %}
            </div>
        </div>

        <div class="row">
            {% for article in articles %}
                <div class="col-lg-8 offset-lg-2">
                    <div class="card mb-3 shadow-sm">
                        <div class="card-body">
                            <h5 class="card-title">
                                <a href="{{ article.url }}" target="_blank">{{ article.title }}</a>
                            </h5>
                            <p class="card-subtitle mb-2 text-muted">
                                <span class="badge bg-secondary me-2">{{ article.category or '综合' }}</span>
                                来源: {{ article.source }} | 抓取时间: {{ article.published_at.strftime('%Y-%m-%d %H:%M') }}
                            </p>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="col-lg-8 offset-lg-2 text-center">
                    <div class="alert alert-secondary" role="alert">
                        暂无资讯，请稍后或运行爬虫。
                    </div>
                </div>
            {% endfor %}
        </div>
    </main>

    <footer class="text-center text-muted py-4">
        <p>&copy; 2024 科讯聚合平台</p>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>